//
//  HDMapLineDrawView.m
//  HDChengDuMuseum
//
//  Created by mac on 16/9/7.
//  Copyright © 2016年 牛的mini. All rights reserved.
//

#import "HDMapLineDrawView.h"

@implementation HDMapLineDrawView

#define Sub_Mutilple 8.0f

- (id)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self)
    {
        self.backgroundColor = [UIColor clearColor];
    }
    return self;
}

- (void)drawPointWithArray:(CGRect)rect
{
    CGContextRef context = UIGraphicsGetCurrentContext();
    CGContextSetLineWidth(context, 2);
    CGContextSetStrokeColorWithColor(context, [Common_Oringe_Color CGColor]);
    
    for (int i=0; i<_pointArray.count; i++) {
        NSValue *pntValue = _pointArray[i];
        CGPoint linePoint = pntValue.CGPointValue;
        
        CGContextMoveToPoint(context, linePoint.x/Sub_Mutilple, linePoint.y/Sub_Mutilple);
        
        NSInteger j=i+1;
        if (_pointArray.count > j)
        {
            NSValue *pntValue = _pointArray[j];
            CGPoint point = pntValue.CGPointValue;
            CGContextAddLineToPoint(context, point.x/Sub_Mutilple, point.y/Sub_Mutilple);
        }
    }
    CGContextStrokePath(context);
    
    CGContextRef nowContext = UIGraphicsGetCurrentContext();

    for (int i=0; i<_pointArray.count; i++) {
        NSValue *pntValue = _pointArray[i];
        CGPoint linePoint = pntValue.CGPointValue;
        // 画点。。
        CGContextFillEllipseInRect(context, CGRectMake(linePoint.x/Sub_Mutilple-1, linePoint.y/Sub_Mutilple-1, 2, 2));
        CGContextSetFillColorWithColor(nowContext, [Common_Oringe_Color CGColor]);
    }
    CGContextStrokePath(nowContext);
}

- (void)drawRect:(CGRect)rect
{
    [self drawPointWithArray:rect];
    // Drawing code
    
    
}

@end
